package tfts

// todo 存在切换形态前施法会在边界条件时被吞bug
type Form struct {
	Hook
	*championMeta        // 只在形态期间生效的属性
	id            string // uuid
	attached      *Fight
	mana          float64
	remain        int
	end           int // 时间剩余，需要高精度所以不使用remain
	ManaLess      bool
	LockSpeed     bool
	SpeedToAd     int
}

func (f *Form) handle(event Event) {
	if !f.match(event) || f.remain <= 0 {
		return
	}
	f.remain--
	if f.remain == 0 && f.championMeta.Next != nil {
		next := f.championMeta.Next
		actionLog("%4.1f秒:形态[-%s-] 切换到 形态[-%s-]\n", f.attached.Current(), f.name, next.name)
		next.attach(f.attached)
	}
}

func (f *Form) valid() bool {
	if f.event == Noop {
		return true
	}
	if f.match(TimeGoE) {
		return f.end >= f.attached.ticks
	}
	return f.remain > 0 && f.factor > 0
}

// 被动与形态绑定，形态切换则被动失效
func (f *Fight) FormAction(name string, attrs ...*attrMeta) *action {
	a := newAction(attrs...)
	a.HandleCondition(func(fight *Fight) bool {
		return fight.name == name
	})
	a.attach(f)
	return a
}
